﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'companyGetByAppName')
	BEGIN
		DROP  Procedure  companyGetByAppName
	END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[companyGetByAppName] 
	-- Add the parameters for the stored procedure here
	@app_name VARCHAR(50) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT e.Id AS lit_empresa_id, nombre AS lit_empresa_nombre
	FROM ld_general..empresas e
	JOIN lit_aplicacion a ON e.id = a.lit_empresa_id
	WHERE lit_aplicacion_nombre = @app_name
	ORDER BY e.nombre ASC;
END
GO